// 全局message实例
let messageInstance: {
  success: (content: string) => void;
  error: (content: string) => void;
  warning: (content: string) => void;
  info: (content: string) => void;
} | null = null;

/**
 * 设置全局message实例
 * 在App组件中调用此方法来设置message实例
 */
export const setMessageInstance = (instance: typeof messageInstance) => {
  messageInstance = instance;
};

/**
 * 获取全局message实例
 * 如果没有设置实例，则返回一个空的实现
 */
export const getMessageInstance = () => {
  if (messageInstance) {
    return messageInstance;
  }
  
  // 如果没有message实例，返回一个空的实现
  return {
    success: (content: string) => console.log('Success:', content),
    error: (content: string) => console.error('Error:', content),
    warning: (content: string) => console.warn('Warning:', content),
    info: (content: string) => console.info('Info:', content),
  };
};

/**
 * 全局message方法
 */
export const globalMessage = {
  success: (content: string) => getMessageInstance().success(content),
  error: (content: string) => getMessageInstance().error(content),
  warning: (content: string) => getMessageInstance().warning(content),
  info: (content: string) => getMessageInstance().info(content),
};